package mahan.data.model;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.mongodb.DBObject;

public class Order implements KeyValuePair {

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static Order from(DBObject dbo) {
		Map map = dbo.toMap();
		int id = (Integer) map.get("id");
		int cid = (Integer) map.get("cid");
		Date enteredOn = (Date) map.get("enter");
		Order order = new Order(id, cid, enteredOn);
		order.put(map);
		return order;
	}

	private int id;
	private int customerID;
	private String shippingAddress;
	private String shippingCity;
	private String shippingState;
	private String shippingCountry = "US";
	private String shippingZip;

	private String shippingPhone;
	private String shippingEmail;
	private double countyTax;

	private double stateTax;
	private double countryTax;

	private Date enteredOn;

	private Date fulfilledOn;
	private String status;
	private double totalCost;

	private double discount;

	private double shippingCost;

	public Order(int id, int custID, Date enteredOn) {
		this.id = id;
		this.customerID = custID;
		this.enteredOn = enteredOn;
	}

	public Map<String, ?> get() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("cid", customerID);
		map.put("sadd", shippingAddress);
		map.put("scity", shippingCity);
		map.put("sstate", shippingState);
		map.put("sctry", shippingCountry);
		map.put("szip", shippingZip);
		map.put("sph", shippingPhone);
		map.put("semail", shippingEmail);
		map.put("countyTax", countyTax);
		map.put("stateTax", stateTax);
		map.put("ctryTax", countryTax);
		map.put("enter", enteredOn);
		map.put("fulfill", fulfilledOn);
		map.put("status", status);
		map.put("cost", totalCost);
		map.put("disc", discount);
		map.put("scost", shippingCost);
		return map;
	}

	public double getCountryTax() {
		return countryTax;
	}

	public double getCountyTax() {
		return countyTax;
	}

	public int getCustomerID() {
		return customerID;
	}

	public double getDiscount() {
		return discount;
	}

	public Date getEnteredOn() {
		return enteredOn;
	}

	public Date getFulfilledOn() {
		return fulfilledOn;
	}

	public int getId() {
		return id;
	}

	public String getShippingAddress() {
		return shippingAddress;
	}

	public String getShippingCity() {
		return shippingCity;
	}

	public double getShippingCost() {
		return shippingCost;
	}

	public String getShippingCountry() {
		return shippingCountry;
	}

	public String getShippingEmail() {
		return shippingEmail;
	}

	public String getShippingPhone() {
		return shippingPhone;
	}

	public String getShippingState() {
		return shippingState;
	}

	public String getShippingZip() {
		return shippingZip;
	}

	public double getStateTax() {
		return stateTax;
	}

	public String getStatus() {
		return status;
	}

	public double getTotalCost() {
		return totalCost;
	}

	public void put(Map<String, ?> map) {
		id = (Integer) map.get("id");
		customerID = (Integer) map.get("cid");
		shippingAddress = (String) map.get("sadd");
		shippingCity = (String) map.get("scity");
		shippingState = (String) map.get("sstate");
		shippingCountry = (String) map.get("sctry");
		shippingZip = (String) map.get("szip");
		shippingPhone = (String) map.get("sph");
		shippingEmail = (String) map.get("semail");
		countyTax = (Double) map.get("countyTax");
		stateTax = (Double) map.get("stateTax");
		countryTax = (Double) map.get("ctryTax");
		enteredOn = (Date) map.get("enter");
		fulfilledOn = (Date) map.get("fulfill");
		status = (String) map.get("status");
		totalCost = (Double) map.get("cost");
		discount = (Double) map.get("disc");
		shippingCost = (Double) map.get("scost");
	}

	public void setCountryTax(double countryTax) {
		this.countryTax = countryTax;
	}

	public void setCountyTax(double countyTax) {
		this.countyTax = countyTax;
	}

	public void setDiscount(double discount) {
		this.discount = discount;
	}

	public void setEnteredOn(Date enteredOn) {
		this.enteredOn = enteredOn;
	}

	public void setFulfilledOn(Date finishedOn) {
		this.fulfilledOn = finishedOn;
	}

	public void setShippingAddress(String shippingAddress) {
		this.shippingAddress = shippingAddress;
	}

	public void setShippingCity(String shippingCity) {
		this.shippingCity = shippingCity;
	}

	public void setShippingCost(double shippingCost) {
		this.shippingCost = shippingCost;
	}

	public void setShippingCountry(String shippingCountry) {
		this.shippingCountry = shippingCountry;
	}

	public void setShippingEmail(String shippingEmail) {
		this.shippingEmail = shippingEmail;
	}

	public void setShippingPhone(String shippingPhone) {
		this.shippingPhone = shippingPhone;
	}

	public void setShippingState(String shippingState) {
		this.shippingState = shippingState;
	}

	public void setShippingZip(String shippingZip) {
		this.shippingZip = shippingZip;
	}

	public void setStateTax(double stateTax) {
		this.stateTax = stateTax;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public void setTotalCost(double totalCost) {
		this.totalCost = totalCost;
	}
}